Skip to content

scripts: build-tools.sh: Use getopts, breakdown script to functions - #2657

Merged
lgirdwood merged 1 commit into
thesofproject:masterfrom
crazoes:getopts-build-tools
Apr 2, 2020
Merged

lgirdwood merged 1 commit into
thesofproject:masterfrom
crazoes:getopts-build-tools

Conversation

@crazoes

@crazoes crazoes commented Mar 28, 2020

Copy link
Copy Markdown
Contributor

Use getopts to parse the arguments instead of manual parsing to leave no
room for errors, bugs, and inconsistent conventions introduced by custom
implementation.

Signed-off-by: Shreeya Patel shreeya.patel23498@gmail.com

@crazoes
crazoes requested a review from jajanusz as a code owner March 28, 2020 10:03
@crazoes

crazoes commented Mar 28, 2020

Copy link
Copy Markdown
Contributor Author

As part of refactoring to use getopts - #2631
Also, while testing this script, I noticed #2656

@lgirdwood
lgirdwood requested a review from marc-hb March 29, 2020 19:22

@marc-hb marc-hb left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor comment, all the rest looks fine. However:

  • you're changing the behavior slightly: now the user can't build the fuzzer first and the tests second.
  • as this script is very short, you rewrote more than half of its lines.

So would you mind pushing the cleanup one step further and add a main() function and local DO_BUILD_TEST etc. variables? See rationale at #2606 (comment)

Comment thread scripts/build-tools.sh Outdated

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least a warning, preferably a fatal error.

@marc-hb
marc-hb requested review from ranj063 and singalsu March 30, 2020 04:28
@crazoes

crazoes commented Mar 30, 2020 •

Copy link
Copy Markdown
Contributor Author

you're changing the behavior slightly: now the user can't build the fuzzer first and the tests second.

I checked the earlier code and you are right, the order of options is infact affecting the execution of the script. Is that by design?

However, do we really want our scripts to be options/arguments order sensitive? Seems pretty weird to me that the order of options matter and change the execution of script. This is just too subtle a information that will not be reflected to anyone who is just using the script following the help. Maybe it makes sense to first build fuzzer and then the tests.

@marc-hb

marc-hb commented Mar 30, 2020

Copy link
Copy Markdown
Collaborator

I checked the earlier code and you are right, the order of options is infact affecting the execution of the script. Is that by design?

I suspect not but I don't know, I'm new here. I copied the author (based on git blame).

This was just an example of you cleaning the script beyond merely switching to getopts. Might as well go all the way.

@jajanusz

Copy link
Copy Markdown
Contributor

I checked the earlier code and you are right, the order of options is infact affecting the execution of the script. Is that by design?

I suspect not but I don't know, I'm new here. I copied the author (based on git blame).

This was just an example of you cleaning the script beyond merely switching to getopts. Might as well go all the way.

Order shouldn't change execution, but there is one exception - if you pass the same argument 2nd time then it should be overwrittene. So prog -a 1 -b 2 and prog -b 2 -a 1 should give the same result, but prog -a 1 -b 2 -a 3 should ignore -a 1 part. For example in gcc, someone can pass -stdlib -nostdlib and it will disable stdlib.

@crazoes
crazoes force-pushed the getopts-build-tools branch from 82dd56d to 149e883 Compare April 1, 2020 10:35
@crazoes crazoes changed the title scripts: build-tools.sh: Use getopts for parsing arguments scripts: build-tools.sh: Use getopts, breakdown script to functions Apr 1, 2020
@crazoes

crazoes commented Apr 1, 2020

Copy link
Copy Markdown
Contributor Author

I checked the earlier code and you are right, the order of options is infact affecting the execution of the script. Is that by design?

I suspect not but I don't know, I'm new here. I copied the author (based on git blame).
This was just an example of you cleaning the script beyond merely switching to getopts. Might as well go all the way.

Order shouldn't change execution, but there is one exception - if you pass the same argument 2nd time then it should be overwrittene. So prog -a 1 -b 2 and prog -b 2 -a 1 should give the same result, but prog -a 1 -b 2 -a 3 should ignore -a 1 part. For example in gcc, someone can pass -stdlib -nostdlib and it will disable stdlib.

This would be the behavior in the current implementation.

@crazoes

crazoes commented Apr 1, 2020

Copy link
Copy Markdown
Contributor Author

@marc-hb I have broken down the script into functions, using local variables(with few global variables) and using getopts for parsing arguments. Please review.

@marc-hb marc-hb left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much better than the original, thanks! Minor issues below.

Comment thread scripts/build-tools.sh Resolved
Comment thread scripts/build-tools.sh Outdated

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate SCRIPT_DIR definition, you have another one in main().

You can make all these local variables in main() if you prefer.

@crazoes crazoes Apr 1, 2020 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SCRIPT_DIR is accessed in all the three functions, that's why made it global. But yeah, missed the duplicate.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

local in main() is almost the same as global. One difference is when you comment out main() and source the script in your current shell for interactive testing.

-main "$@"
+# main "$@"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, that's good to know. Very different than block scoping you'd see elsewhere. Using local now.

Comment thread scripts/build-tools.sh Resolved
@crazoes
crazoes force-pushed the getopts-build-tools branch from 149e883 to 1afd069 Compare April 1, 2020 18:14
Breakdown script to functions, use local variables, and a main function.

Use getopts to parse the arguments instead of manual parsing to leave no
room for errors, bugs, and inconsistent conventions introduced by custom
implementation.

Signed-off-by: Shreeya Patel <shreeya.patel23498@gmail.com>
@crazoes
crazoes force-pushed the getopts-build-tools branch from 1afd069 to 668d804 Compare April 1, 2020 18:45
@lgirdwood

Copy link
Copy Markdown
Member

CI known issues.

@lgirdwood
lgirdwood merged commit db1bf13 into thesofproject:master Apr 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants